(function(){
    const html=document.documentElement;
   var viewportEl=document.querySelector('meta[name="viewport"]');
    var dpr=window.devicePixelRatio||1;
    var maxwidth=540;
    var minwidth=320;
    dpr=dpr>=3?3:(dpr>=2?2:1);
    html.setAttribute('data-dpr',dpr);
    html.setAttribute('max-width',maxwidth)
    html.setAttribute('min-width',minwidth)
    var scale=1/dpr;
    content='width=device-width,initial-scale='+scale+',maximum-scale='+scale+',minimum-scale='+scale+',user-scalable=no';
    if(viewportEl){
        viewportEl.setAttribute('content',content);
    }else{
        viewportEl=document.createElement('meta');
        viewportEl.setAttribute('name','viewport');
        viewportEl.setAttribute('content',content);
        document.head.appendChild(viewportEl)
    }
    setHw()
    window.onresize=setHw;
    function setHw(){
        var ratio=18.75
        var view=window.innerWidth||html.getBoundingClientRect().width;
        if(maxwidth&&(view/dpr>maxwidth)){
            view=maxwidth*dpr
        }else if(minwidth&&view/dpr<minwidth){
            view=minwidth*dpr
        }
        html.style.fontSize=view/ratio+'px'
    }
})()